<?php
	$css_list[0]['url'] = './tpl/css/article.css';
?>
<!--{template inc/header_n}-->

<div class="main_warp">
    <div class="inventory">
        <!--{template inc/list/list_menu}-->

        <div class="i_righter">
            <p>
                当前位置：<a href="/list.php?action=plan&op=show&id={$pl['id']}">{$pl['tip']}[<?php echo date('Y-m-d', $pl['dateline']); ?>]</a>
                > {$item['name']}[{if $item['flag']}已完成{else}未完成{/if}]
            </p>
            
            <div style="margin-top:10px;">
                {if !$item['shopid']}
                <p>请先绑定商家！</p>
                <p><select id="ordersel">
                    <option value="0">请选择</option>
                    {loop $order_list $v}
                    <option value="{$v['shopid']}|{$v['id']}">{$shopinfos[$v['shopid']]['user_name']}[{$v['ordername']}][单号：{$v['orderid']}]</option>
                    {/loop}
                </select>
                <input type="button" style="padding:2px 6px;" class="green_button" value="绑定" onclick="bindshop()"/>
                </p>
                {else}
                <p>
                    已绑定商家{$shopinfo['user_name']}!
                    {if $item['paystep'] >= 1 && $item['paystep'] < $item['paysteps']}
                    {if $item['isstop']==1}
                    [<span style="color:red;">交易停止 退款成功 请到<a href="/shareinfo.php?action=withdraw">余额</a>里提现</span>]
                    {else}
                    [<span id="unpaywrap" style="color:red;">
                        {if !$item['unpay']}
                        <a href="/list.php?action=plan&op=unpay&id={$item['item_id']}">申请退款</a>
                        {else}
                        申请退款{$unpayinfo['money']}元，商家审核退款中…<a href="javascript:;" onclick="unpay(0)">撤消退款</a>
                        {/if}
                    </span>]
                    {/if}
                    {/if}
                </p>
                {/if}
                <?php $b = false; ?>
                <table class="table_list" width="100%" cellspacing="1" border="0">
                    {loop $item['items'] $k $v}
                    <tr style="background-color:<?php if($k%2==0) {?>#E7ECF0<?php }else{?>#fff<?php }?>;">
                        <td>{$v['name']}</td>
                        {if isset($item['data'][$k])}
                        <td><?php echo date('Y-m-d', $item['data'][$k]['dateline']);?></td>
                        <td>
                            {$v['tips'][$item['data'][$k]['tipid']]}
                            <p style="color:blue;">{$item['data'][$k]['tip']}</p>
                        </td>
                        <td>已完成</td>
                        <?php $flag = isset($v['paystep']) && $v['paystep'] > $item['paystep']; ?>
                        {if $flag && !$b && $item['isstop'] != 1}
                        <?php $b = true; ?>
                        <td>
                            <input type="button" style="padding:2px 6px;width:85px;height:31px;font-size:14px;" class="green_button" value="确认付款" onclick="dopay({$v['paystep']}, this)"/>
                        </td>
                        {elseif isset($v['paystep'])}
                        <td>{if $v['paystep'] > $item['paystep']}待付{else}已付{/if}<?php $arr = array(0,0.3,0.5,0.2);echo $orderinfo['total_fee']*$arr[$v['paystep']]; ?></td>
                        {else}
                        <td>-</td>
                        {/if}
                        {else}
                        <td>-</td>
                        <td>-</td>
                        <td>未完成</td>
                        <td>-</td>
                        {/if}
                    </tr>
                    {/loop}
                </table>
            </div>
        </div>
        <br class="g_clear" />
</div>
<!--{template inc/footer}-->
<script type="text/javascript">
function bindshop() {
    var ids = $('#ordersel').val();
    if(ids == 0) {
        alert('请选择订单');
        return;
    }
    
    $.post('/list.php?action=plan', {ids : ids, dobindshop:1, itemid : {$item['item_id']}}, function(s){
        if(s == '1') {
            location.reload();
        } else {
            alert('绑定失败，请重试');
        }
    });
}

function dopay(paystep, obj) {
    {if $orderinfo['pay_mulit']}
    $.colorbox({
       href:SITE_PATH+'services/service.php?m=article&a=showpay&id={$orderinfo['artid']}',
       width:500,
       height:200
    });
    {else}
    var msg = '';
    if(paystep == 1)
        msg = '确认付款后交易金额的30%将作为订金打入商家账户！';
    else if(paystep == 2)
        msg = '确认付款后交易金额的80%将打入商家账户！';
    else if(paystep == 3)
        msg = '确认付款后全部金额将打入商家账户！';
        
    msg += '\r\n继续付款吗？';
    if(window.confirm(msg)) {
        $.post('/list.php?action=plan', {dopay : 1, paystep : paystep, id : {$item['item_id']}}, function(s) {
            location.reload();
        })
    }
    {/if}
}

function unpay(flag) {
    $.post('/list.php?action=plan', {dounpay : 1, id : {$item['item_id']}, flag : flag}, function(s) {
        if(s == '1') {
            location.reload();
        }
    });
}

function pingka() {
    $.colorbox({
       href:SITE_PATH+'services/service.php?m=article&a=pingka&orderid={$item['orderid']}',
       width:400,
       height:200
    });
}
{if $_GET['subop'] == 'showpingka'}
pingka();
{/if}
</script>